<?php
/**
 * Object Relational Persistence Mapping Class for table: test
 *
 * @package	com.clearhealth
 * @author	ClearHealth Inc.
 */
class Test extends ORDataObject {

	/**#@+
	 * Fields of table: test mapped to class members
	 */
	var $test_id		= '';
	var $room_id		= '';
	var $payment_type   = '';
	var $name			= '';
	var $disabled  		= '';
	var $parent_id          = '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'test';

	/**
	 * Primary Key
	 */
	var $_key = 'test_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'Test';

	/**
	 * Handle instantiation
	 */
	function Test() {
		parent::ORDataObject();
	}

	function get_name() {
		return $this->name;
	}
	function get_room_id() {
		return $this->room_id;
	}
	
	public function listAll() {
		$field	=	L10nHelper::changeField(L10nHelper::getLocale(), 'name');
		$ds = new Datasource_sql();
		$sql = array (
			'cols'	=> "test_id, $field name, parent_id",
			'from'	=> "$this->_table ",
			'where' => 'disabled = 0',
			'orderby'	=> "name");
		$ds->setup($this->_db, $sql);
		return $ds->toArray('test_id', 'name');
	}
	
    public function listAllTest() {
        $field  =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
        
        $ds = new Datasource_sql();
        $sql = array (
            'cols'  => "test_id, $field test_name, parent_id",
            'from'  => $this->_table,
            'where' => 'disabled = 0',
            'orderby'   => "name");
        $ds->setup($this->_db, $sql);
        return $ds->toArray();
    }
	
	public function listAllFullInfo() {
	    $field  =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
		
		$ds = new Datasource_sql();
		$sql = array (
			'cols'	=> "test_id, T.$field AS test_name, R.$field AS room_name, T.payment_type, T.disabled, parent_id",
			'from'	=> "$this->_table T
			         LEFT JOIN room R ON T.room_id = R.room_id",
			'orderby'	=> "T.name");
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}

}
?>
